package com.supor.aiot.home.apdater;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.baseconfig.common.utils.Logc;
import com.android.baseconfig.common.utils.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.supor.aiot.common.app.Constants;
import com.supor.aiot.common.entity.BaseDeviceData;
import com.supor.aiot.common.entity.ChiefMachineData;
import com.supor.aiot.common.entity.DeviceInfo;
import com.supor.aiot.common.entity.OvenData;
import com.supor.aiot.common.entity.RiceCookerData;
import com.supor.aiot.common.entity.WaterPurifierData;
import com.supor.aiot.common.utils.BitmapUtil;
import com.supor.aiot.home.R;
import com.supor.nfc.lib.utils.NfcUtils;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import androidx.core.content.res.ResourcesCompat;

/**
 * ---------------------------------------------------------------- <br>
 * Copyright (C) 2014-2020, by het, Shenzhen, All rights reserved.  <br>
 * ---------------------------------------------------------------- <br>
 * <p>
 * 描述: BindDeviceAdapter：绑定的设备的adapter <br>
 * 作者: lei <br>
 * 日期: 2021/7/16 <br>
 */
public class BindDeviceAdapter extends BaseQuickAdapter<DeviceInfo, BaseViewHolder> {

    public BindDeviceAdapter(List<DeviceInfo> dataList) {
        super(R.layout.item_bind_device, dataList);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, DeviceInfo data) {

        if (TextUtils.isEmpty(data.devAlias)) {
            /*
             * 此版本 2.0.2 去掉mac地址后缀
             */
//            if (data.mac != null && data.mac.length() > 4) {
//                String suffix = data.mac.substring(data.mac.length() - 4);
//                if (!TextUtils.isEmpty(data.crmModelName)) {
//                    holder.setText(R.id.tv_name, data.crmModelName + suffix);
//                } else {
//                    holder.setText(R.id.tv_name, data.productName + suffix);
//                }
//            } else {
//                if (!TextUtils.isEmpty(data.crmModelName)) {
//                    holder.setText(R.id.tv_name, data.crmModelName);
//                } else {
//                    holder.setText(R.id.tv_name, data.productName);
//                }
//            }
            if (!TextUtils.isEmpty(data.crmModelName)) {
                holder.setText(R.id.tv_name, data.crmModelName);
            } else {
                holder.setText(R.id.tv_name, data.productName);
            }

        } else {
            holder.setText(R.id.tv_name, data.devAlias);
        }
        // holder.setVisible(R.id.view_offline, false);
        // if (TextUtils.isEmpty(data.offStatusText)) {
        //     holder.setText(R.id.tv_new_recipe, "");
        // } else {
        //     holder.setText(R.id.tv_new_recipe, data.offStatusText);
        // }
        holder.setVisible(R.id.iv_status, true);

        ImageView icon = holder.getView(R.id.iv_icon);
        BitmapUtil.loadUrl(data.modelPicture, icon, BitmapUtil.options5);
        if (Constants.Type.TYPE_CHEF_MACHINE.equalsIgnoreCase(data.type)) {
            // holder.setImageResource(R.id.iv_icon, R.mipmap.ic_device_chief_machine);
            if (TextUtils.isEmpty(data.offStatusText)) {
                holder.setText(R.id.tv_label, Constants.Value.CHEF_MACHINE_LABEL);
            } else {
                holder.setText(R.id.tv_label, data.offStatusText);
            }
            if (data.deviceData != null) {
                ChiefMachineData deviceData = (ChiefMachineData) data.deviceData;
                // Logc.d("convert: " + deviceData.toString());
                if (data.status) {
                    if (deviceData.machineStatus != 0 && deviceData.machineStatus != 5) {
                        // 上位机显示： 0 待机；1 预约；2 保温；3 烹饪中； 4 烹饪结束保温；5 已经完成 6-10 预留；
                        if (deviceData.wifiWarning || deviceData.weightWarning || deviceData.wronglidWarning
                                || deviceData.bottomWarning || deviceData.lidWarning
                                || deviceData.pbWarning || deviceData.topWarning) {
                            holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_error);
                        } else if (deviceData.machineStatus == 1) {
                            holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_appointment);
                        } else {
                            holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_on);
                        }
                        showLabel(holder, false, data.status);
                        // 食谱名？
                        // holder.setText(R.id.tv_name, deviceData.recipeName);
                        showTime(holder, deviceData, null);

                        TextView tvFire = holder.getView(R.id.tv_fire);
                        String display = "";

                        // 取低5位
                        int workStatus = deviceData.workStatus & 0x1F;
                        // 1-7显示压力，14，15，17，20显示温度，其他显示火力
                        // 15烘烤和20清洗功能上报设定温度，14保温和17低温功能上报实时温度
                        if (workStatus >= 1 && workStatus <= 7) {
                            display = deviceData.realPressureValue + " kPa";
                            tvFire.setCompoundDrawablesWithIntrinsicBounds(
                                    ResourcesCompat.getDrawable(holder.itemView.getResources(),
                                            R.mipmap.ic_press, null),
                                    null, null, null);
                        } else if (workStatus == 15 || workStatus == 20) {
                            display = deviceData.setTempValue + " °C";
                            tvFire.setCompoundDrawablesWithIntrinsicBounds(
                                    ResourcesCompat.getDrawable(holder.itemView.getResources(),
                                            R.mipmap.ic_real_temp, null),
                                    null, null, null);
                        } else if (workStatus == 14 || workStatus == 17) {
                            display = deviceData.realTempValue + " °C";
                            tvFire.setCompoundDrawablesWithIntrinsicBounds(
                                    ResourcesCompat.getDrawable(holder.itemView.getResources(),
                                            R.mipmap.ic_real_temp, null),
                                    null, null, null);
                        } else {
                            if (deviceData.powerScale == 1) {
                                display = "小火力";
                            } else if (deviceData.powerScale == 2) {
                                display = "中火力";
                            } else {
                                display = "大火力";
                            }
                            tvFire.setCompoundDrawablesWithIntrinsicBounds(
                                    ResourcesCompat.getDrawable(holder.itemView.getResources(),
                                            R.mipmap.ic_fire, null),
                                    null, null, null);
                        }

                        tvFire.setText(display);

                        String stri;
                        if (deviceData.realBladeStatus == 1) {
                            stri = "低转速";
                        } else if (deviceData.realBladeStatus == 2) {
                            stri = "中转速";
                        } else if (deviceData.realBladeStatus == 3) {
                            stri = "高转速";
                        } else {
                            stri = "不搅拌";
                        }
                        TextView tvStri = holder.getView(R.id.tv_stri);
                        tvStri.setText(stri);

                        if (!deviceData.onOffStatus) {
                            holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_power_off);
                        }

                        return;
                    } else {
                        if (deviceData.wifiWarning || deviceData.weightWarning || deviceData.wronglidWarning
                                || deviceData.bottomWarning || deviceData.lidWarning
                                || deviceData.pbWarning || deviceData.topWarning) {
                            holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_error);
                        } else if (!deviceData.onOffStatus) {
                            holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_power_off);
                        } else {
                            holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_standby);
                        }
                    }
                } else {
                    holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_off);
                    // holder.setImageResource(R.id.iv_icon, R.mipmap.ic_device_chief_machine_off);
                    // holder.setVisible(R.id.view_offline, true);
                }
            } else {
                if (!data.status) {
                    holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_off);
                    // holder.setImageResource(R.id.iv_icon, R.mipmap.ic_device_chief_machine_off);
                    // holder.setVisible(R.id.view_offline, true);
                } else {
                    holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_standby);
                }
            }

        } else if (Constants.Type.TYPE_OVEN.equalsIgnoreCase(data.type)) {
            // holder.setImageResource(R.id.iv_icon, R.mipmap.ic_device_oven);
            if (TextUtils.isEmpty(data.offStatusText)) {
                holder.setText(R.id.tv_label, Constants.Value.OVEN_LABEL);
            } else {
                holder.setText(R.id.tv_label, data.offStatusText);
            }
            if (data.deviceData != null) {
                OvenData deviceData = (OvenData) data.deviceData;
                Logc.d("OvenData: " + deviceData.toString());
                if (data.status) {
                    // 0 关机状态|1 待机中|2 暂停中|3 预热中|4 烹饪中|5 烹饪完成|6 故障中|7-20 预留
                    if (deviceData.machineStatus == 6) {
                        holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_error);
                    } else if (deviceData.machineStatus == 1 || deviceData.machineStatus == 5) {
                        holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_standby);
                    } else if (deviceData.machineStatus == 0) {
                        holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_power_off);
                    } else {
                        if (deviceData.machineStatus == 2) {
                            holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_pause);
                        } else if (deviceData.waterBox == 1) {
                            holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_pause);
                        } else if (deviceData.machineStatus == 3) {
                            holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_preheat);
                        } else {
                            holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_on);
                        }
                        // 食谱名？
                        // holder.setText(R.id.tv_name, deviceData.recipeName);
                        int h = deviceData.workTime / 60;
                        String hour = "";
                        String min = "";

                        String prefix = "";
                        int m = (deviceData.workTime) % 60 + 1;
                        if (m > 60) {
                            hour = prefix + StringUtils.getFormatHour(h + 1);
                            min = StringUtils.getFormatMin(0);
                        } else {
                            hour = prefix + StringUtils.getFormatHour(deviceData.workTime / 60);
                            min = StringUtils.getFormatMin((int) ((Math.ceil(deviceData.workTime) % 60)));
                        }

                        Logc.i("showTime: " + hour + ", " + min);
                        holder.setText(R.id.tv_remain_time_hour, hour);
                        holder.setText(R.id.tv_remain_time_min, min);

                        // showTime(holder, deviceData, "剩余时间 ");


                        String temp = deviceData.realTempValue + "°C";
                        TextView tvStri = holder.getView(R.id.tv_stri);
                        tvStri.setText(temp);
                        if (deviceData.machineStatus == 2 || deviceData.machineStatus == 3) {
                            tvStri.setCompoundDrawablesWithIntrinsicBounds(
                                    ResourcesCompat.getDrawable(holder.itemView.getResources(),
                                            R.mipmap.ic_real_temp, null),
                                    null, null, null);
                        } else {
                            tvStri.setCompoundDrawablesWithIntrinsicBounds(
                                    ResourcesCompat.getDrawable(holder.itemView.getResources(),
                                            R.mipmap.ic_real_temp, null),
                                    null, null, null);
                        }

                        showLabel(holder, false, data.status);

                        String display = "";
                        int workStatus = deviceData.workStatus;
                        // 3,4,5显示加热，其他不显示
                        if (workStatus == 1) {
                            display = "纯蒸模式";
                        } else if (workStatus == 2) {
                            display = "速蒸模式";
                        } else if (workStatus >= 3 && workStatus <= 5) {
                            display = "纯烤模式";
                            // if (deviceData.machineStatus != 2) {
                            //     holder.setText(R.id.tv_fire, display);
                            //     holder.getView(R.id.tv_fire).setVisibility(View.VISIBLE);
                            // } else {
                            //     holder.getView(R.id.tv_fire).setVisibility(View.GONE);
                            // }
                        } else if (workStatus == 6) {
                            display = "嫩烤模式";
                        } else if (workStatus == 7) {
                            display = "空炸模式";
                        } else if (workStatus == 8) {
                            display = "风干模式";
                        } else if (workStatus == 9) {
                            display = "煲炖模式";
                        } else if (workStatus == 10) {
                            display = "发酵模式";
                        } else {
                            holder.getView(R.id.tv_fire).setVisibility(View.GONE);
                            return;
                        }
                        holder.setText(R.id.tv_fire, display);
                        holder.getView(R.id.tv_fire).setVisibility(View.VISIBLE);
                        return;
                    }
                }
            } else {
                if (!data.status) {
                    holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_off);
                    // holder.setImageResource(R.id.iv_icon, R.mipmap.ic_device_oven_off);
                    // holder.setVisible(R.id.view_offline, true);
                } else {
                    holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_standby);
                }
            }
        } else if (Constants.Type.TYPE_RICE_COOKER.equalsIgnoreCase(data.type)) {
            if (TextUtils.isEmpty(data.offStatusText)) {
                holder.setText(R.id.tv_label, Constants.Value.RICE_COOKER_LABEL);
            } else {
                holder.setText(R.id.tv_label, data.offStatusText);
            }
            if (data.deviceData != null) {
                RiceCookerData deviceData = (RiceCookerData) data.deviceData;
                Logc.d("RiceCookerData: " + deviceData.toString());
                if (data.status) {
                    // 0 待机中|1 预约中|2 烹饪中|3 烹饪完成|4 保温中|5 故障中|6 预热中|7 吸水中|8 加热中|9 沸腾中|10 焖饭中
                    int machineStatusIcon;
                    switch (deviceData.machineStatus) {
                        case 0:
                            machineStatusIcon = R.mipmap.ic_status_standby;
                            break;
                        case 1:
                            machineStatusIcon = R.mipmap.ic_status_appointment;
                            break;
                        case 2:
                            machineStatusIcon = R.mipmap.ic_status_working;
                            break;
                        case 3:
                        case 4:
                            machineStatusIcon = R.mipmap.ic_status_holding;
                            break;
                        case 5:
                            machineStatusIcon = R.mipmap.ic_status_error;
                            break;
                        case 6:
                            machineStatusIcon = R.mipmap.ic_status_preheat;
                            break;
                        case 7:
                            machineStatusIcon = R.mipmap.ic_status_watering;
                            break;
                        case 8:
                            machineStatusIcon = R.mipmap.ic_status_heating;
                            break;
                        case 9:
                            machineStatusIcon = R.mipmap.ic_status_boiling;
                            break;
                        case 10:
                            machineStatusIcon = R.mipmap.ic_status_risotto;
                            break;
                        default:
                            machineStatusIcon = R.mipmap.ic_status_off;
                            break;
                    }
                    holder.setImageResource(R.id.iv_status, machineStatusIcon);

                    // 温度、时间、烹饪模式显示（机器在线时，待机、预约中和故障状态不显示）
                    if (deviceData.machineStatus != 0 && deviceData.machineStatus != 1 && deviceData.machineStatus != 5) {

                        showLabel(holder, false, data.status);

                        // 柴火饭|快煮饭|煲仔饭|热饭 时间显示逻辑
                        // 1、热饭|煲仔饭不显示时间
                        if (deviceData.workStatus == 6 || deviceData.workStatus == 13) {
                            hideTime(holder, false);
                        } else {
                            // 2、如果预约时间为0，柴火饭|快煮饭不显示时间
                            if (deviceData.workStatus == 4 || deviceData.workStatus == 5) {
                                if (deviceData.appointmentTime == 0) {
                                    hideTime(holder, false);
                                } else {

                                    hideTime(holder, true);
                                    // 显示预约时间
                                    String hour, min;
                                    String prefix = "";

                                    hour = prefix + StringUtils.getFormatHour(deviceData.appointmentTime / 60);
                                    min = StringUtils.getFormatMin((int) ((Math.ceil(deviceData.appointmentTime) % 60)));

                                    Logc.i("showTime: " + hour + ", " + min);
                                    holder.setText(R.id.tv_remain_time_hour, hour);
                                    holder.setText(R.id.tv_remain_time_min, min);
                                }

                            } else {

                                hideTime(holder, true);
                                // 3、预约时间 >0，显示预约时间，否则显示剩余工作时间
                                String hour, min;
                                String prefix = "";

                                hour = prefix + StringUtils.getFormatHour(deviceData.workTime / 60);
                                min = StringUtils.getFormatMin((int) ((Math.ceil(deviceData.workTime) % 60)));

                                if (deviceData.appointmentTime > 0) {
                                    hour = prefix + StringUtils.getFormatHour(deviceData.appointmentTime / 60);
                                    min = StringUtils.getFormatMin((int) ((Math.ceil(deviceData.appointmentTime) % 60)));
                                }

                                if (deviceData.machineStatus == 3 || deviceData.workStatus == 14) {
                                    hour = prefix + StringUtils.getFormatHour(deviceData.holdingTime / 60);
                                    min = StringUtils.getFormatMin((int) ((Math.ceil(deviceData.holdingTime) % 60)));
                                }

                                Logc.i("showTime: " + hour + ", " + min);
                                holder.setText(R.id.tv_remain_time_hour, hour);
                                holder.setText(R.id.tv_remain_time_min, min);
                            }
                        }

                        String temp = deviceData.currentTemperature + "°C";
                        TextView tvStri = holder.getView(R.id.tv_stri);
                        tvStri.setText(temp);
                        tvStri.setCompoundDrawablesWithIntrinsicBounds(
                                ResourcesCompat.getDrawable(holder.itemView.getResources(),
                                        R.mipmap.ic_real_temp, null),
                                null, null, null);

                        String display = "";
                        switch (deviceData.workStatus) {
                            case 1:
                                display = "熬粥";
                                break;
                            case 2:
                                display = "稀饭";
                                break;
                            case 3:
                                display = "杂粮粥";
                                break;
                            case 4:
                                display = "柴火饭";
                                break;
                            case 5:
                                display = "快煮饭";
                                break;
                            case 6:
                                display = "煲仔饭";
                                break;
                            case 7:
                                display = "云美食";
                                break;
                            case 8:
                                display = "香浓汤";
                                break;
                            case 9:
                                display = "高温蒸";
                                break;
                            case 10:
                                display = "蛋糕";
                                break;
                            case 11:
                                display = "面包";
                                break;
                            case 12:
                                display = "烤鸡翅";
                                break;
                            case 13:
                                display = "热饭";
                                break;
                            case 14:
                                display = "保温";
                                break;
                            default:
                                break;
                        }
                        // 处理美食菜谱
                        if (deviceData.recipeID > 0 && !TextUtils.isEmpty(deviceData.recipeName)) {
                            display = deviceData.recipeName;
                        }
                        holder.setText(R.id.tv_fire, display);
                        return;
                    }
                } else {
                    holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_off);
                    // 清掉之前保存的机器数据
                    data.deviceData = null;
                }
            } else {
                if (!data.status) {
                    holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_off);
                    // holder.setImageResource(R.id.iv_icon, R.mipmap.ic_device_oven_off);
                    // holder.setVisible(R.id.view_offline, true);
                } else {
                    holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_standby);
                }
            }
        } else if (Constants.Type.TYPE_WATER_PURIFIER.equalsIgnoreCase(data.type)) {
            if (TextUtils.isEmpty(data.offStatusText)) {
                holder.setText(R.id.tv_label, Constants.Value.WATER_PURIFIER);
            } else {
                holder.setText(R.id.tv_label, data.offStatusText);
            }
            if (data.deviceData != null) {
                WaterPurifierData deviceData = (WaterPurifierData) data.deviceData;
                Logc.d("data: " + deviceData.toString());
                Logc.d("data: " + data.status);
                if (data.status) {
                    if (deviceData.alarm_communications_failure || deviceData.alarm_pcb || deviceData.alarm_tap
                            || deviceData.alarm_water_empty || deviceData.alarm_water_leakage
                            || deviceData.alarm_water_temperature_in || deviceData.alarm_water_temperature_out
                            || deviceData.reserve_error || deviceData.reserve_error2
                            || deviceData.alarm_heating_protect || deviceData.alarm_lack_water
                            || deviceData.alarm_low_water || deviceData.alarm_tds_error) {
                        holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_error);
                    } else if (!deviceData.power) {
                        holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_power_off);
                    } else {
                        holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_on);
                    }
                }
            } else {
                if (!data.status) {
                    holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_off);
                } else if (!data.onoffStatus) {
                    holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_power_off);
                } else {
                    holder.setImageResource(R.id.iv_status, R.mipmap.ic_status_on);
                }
            }
        } else if (Constants.Type.BLENDER_Q8.equalsIgnoreCase(data.model)
                || Constants.Type.TYPE_ELECTRIC_SAUCEPAN_C18.equalsIgnoreCase(data.model)
                || Constants.Type.TYPE_VOLTAGE_POT.equalsIgnoreCase(data.model)
                || Constants.Type.TYPE_VOLTAGE_POT_C100.equalsIgnoreCase(data.model)
                || Constants.Type.TYPE_ELECTRIC_SAUCEPAN.equalsIgnoreCase(data.model)
                || Constants.Type.TYPE_BLENDER_66R.equalsIgnoreCase(data.model)
                || Constants.Type.TYPE_BLENDER_65S.equalsIgnoreCase(data.model)
                || Constants.Type.TYPE_BLENDER_905S.equalsIgnoreCase(data.model)
                || Constants.Type.TYPE_BLENDER_906R.equalsIgnoreCase(data.model)) {
            /*
             * 此版本 2.0.2 去掉mac地址后缀
             */
//            if (TextUtils.isEmpty(data.devAlias)) {
//                if (data.mac != null && data.mac.length() > 4) {
//                    String suffix = data.mac.substring(0, 4);
//                    if (!TextUtils.isEmpty(data.crmModelName)) {
//                        holder.setText(R.id.tv_name, data.crmModelName + suffix);
//                    } else {
//                        holder.setText(R.id.tv_name, data.productName + suffix);
//                    }
//                } else {
//                    if (!TextUtils.isEmpty(data.crmModelName)) {
//                        holder.setText(R.id.tv_name, data.crmModelName);
//                    } else {
//                        holder.setText(R.id.tv_name, data.productName);
//                    }
//                }
//            }
            if (TextUtils.isEmpty(data.offStatusText)) {
                holder.setText(R.id.tv_label, Constants.Value.BLENDER_LABEL);
            } else {
                holder.setText(R.id.tv_label, data.offStatusText);
            }
            // 如果手机不支持NFC
            if (NfcUtils.NFC_STATE == 1) {
                holder.setText(R.id.tv_label, R.string.no_nfc);
            }
            holder.setVisible(R.id.iv_status, false);
        } else {
            if (!TextUtils.isEmpty(data.offStatusText)) {
                holder.setText(R.id.tv_label, data.offStatusText);
            }
        }

        showLabel(holder, true, data.status);

    }

    private void showLabel(@NotNull BaseViewHolder holder, boolean show, boolean offline) {
        // if (offline) {
        //     holder.setTextColorRes(R.id.tv_name, R.color.content_default);
        //     holder.setTextColorRes(R.id.tv_label, R.color.content_assist);
        // } else {
        //     holder.setTextColorRes(R.id.tv_name, R.color.content_assist);
        //     holder.setTextColorRes(R.id.tv_label, R.color.color_CCCCCC);
        // }
        if (show) {
            holder.getView(R.id.iv_remain_time_hour).setVisibility(View.INVISIBLE);
            holder.getView(R.id.tv_remain_time_hour).setVisibility(View.INVISIBLE);
            holder.getView(R.id.tv_twinkle).setVisibility(View.INVISIBLE);
            holder.getView(R.id.tv_remain_time_min).setVisibility(View.INVISIBLE);
            holder.getView(R.id.tv_fire).setVisibility(View.INVISIBLE);
            holder.getView(R.id.tv_stri).setVisibility(View.INVISIBLE);
            holder.setVisible(R.id.tv_label, true);
        } else {
            holder.getView(R.id.tv_label).setVisibility(View.GONE);
            holder.setVisible(R.id.iv_remain_time_hour, true);
            holder.setVisible(R.id.tv_remain_time_hour, true);
            holder.setVisible(R.id.tv_twinkle, true);
            holder.setVisible(R.id.tv_remain_time_min, true);
            holder.setVisible(R.id.tv_fire, true);
            holder.setVisible(R.id.tv_stri, true);
        }
    }

    private void showTime(@NotNull BaseViewHolder holder, BaseDeviceData deviceData, String prefix) {
        int h = deviceData.workTime / 3600;
        String hour = "";
        String min = "";
        if (prefix == null) {
            prefix = "";
        }
        float m = (deviceData.workTime / 60.0f) % 60 + 1;
        if (m > 60) {
            hour = prefix + StringUtils.getFormatHour(h + 1);
            min = StringUtils.getFormatMin(0);
        } else {
            hour = prefix + StringUtils.getFormatHour(deviceData.workTime / 3600);
            min = StringUtils.getFormatMin((int) ((Math.ceil(deviceData.workTime / 60.0f)) % 60));
        }

        Logc.d("showTime: " + hour + ", " + min);
        holder.setText(R.id.tv_remain_time_hour, hour);
        holder.setText(R.id.tv_remain_time_min, min);
    }

    private void hideTime(@NotNull BaseViewHolder holder, boolean isShow) {
        if (isShow) {
            holder.getView(R.id.iv_remain_time_hour).setVisibility(View.VISIBLE);
            holder.getView(R.id.tv_remain_time_hour).setVisibility(View.VISIBLE);
            holder.getView(R.id.tv_twinkle).setVisibility(View.VISIBLE);
            holder.getView(R.id.tv_remain_time_min).setVisibility(View.VISIBLE);

            holder.getView(R.id.vw_blank).setVisibility(View.VISIBLE);
        } else {
            holder.getView(R.id.iv_remain_time_hour).setVisibility(View.GONE);
            holder.getView(R.id.tv_remain_time_hour).setVisibility(View.GONE);
            holder.getView(R.id.tv_twinkle).setVisibility(View.GONE);
            holder.getView(R.id.tv_remain_time_min).setVisibility(View.GONE);

            holder.getView(R.id.vw_blank).setVisibility(View.GONE);
        }
    }
}
